Leaflet draw delete features with property - leaflet

Is it possible to delete multiple features from geojson at once by checking property value?
Using for example code below or using Leaflet draw?
function deleteArea() {
var layers = featureGroup.getLayers();
for (var i = 0; i < layers.length; i++) {
if (layers[i].feature.properties.N == 1)
{
"DELETE?" layer[i];
};
}
};
I have big map and some markers have property: feature.properties.N=1. I can delete them using leaflet draw clicking one by one because I changed marker to red for those layers. But it takes some time.. Is it possible to to this at once?
Thank you very much for your time !

Sure you can simply remove the markers from the map / featuregroup with layer.removeFrom(featureGroup)
function deleteArea() {
var layers = featureGroup.getLayers();
for (var i = 0; i < layers.length; i++) {
if (layers[i].feature.properties.N == 1){
layer[i].removeFrom(featureGroup);
};
}
};
PS: I prefer to use Leaflet-Geoman because it is more modern and is still being supported and gets new features

Related

Setting material in Unity in run time issue

When I change material in runtime with this it does not work
expoSceneLarge.GetComponent<Renderer>().materials[0] = availableMaterials[selectedMaterialIndex];
however using this
expoSceneLarge.GetComponent<Renderer>().material = availableMaterials[selectedMaterialIndex];
material is being changed in run time.
What confuses me is that material, according to Unity return the first element in materials attached to renderer, so why materials[0] does not work?
Found a solution.
I has to create new array of materials, change the once I was interested in and the assign whole array to mesh renderer. Here is a a full code for future reference.
var newMaterials = new Material[_expoMaterials.Count()];
for(int i = 0; i < newMaterials.Count(); i++)
{
// i = 1 for floor
if(i == 1)
{
newMaterials[i] = availableMaterials[selectedMaterialIndex];
}
else
{
newMaterials[i] = _expoMaterials[i];
}
}
expoSceneLarge.GetComponent<MeshRenderer>().materials = newMaterials;

Sprite Grid Positioning issue cocosd-js 3.16

I am making a 2d(25x20) grid of sprites. But somehow sprites are getting re positioned by itself.enter image description here
makeLandBlocksMatrix : function () {
this.LAND_BLOCK_TAG = 1;
var blockCounter = 0;
var prices = MMMapData.getPrices();
this._blocks = MMUtility.createArray(MMConstants.totalNoRowsPerMap,MMConstants.totalNoColsPerMap);
for (var i = 0; i< MMConstants.totalNoRowsPerMap; i++){
for (var j = 0; j< MMConstants.totalNoColsPerMap; j++){
var block = new MMLandBlockSprite();
block.initWithData(res.BlockBlack,prices[blockCounter],this.LAND_BLOCK_TAG);
block.setPosition(cc.p(block.getContentSize().width*0.5 + i * block.getContentSize().width * 1.0, (this._size.height - block.getContentSize().height*0.5) - j * block.getContentSize().height * 1.0));
this.addChild(block);
block.setBg();
block._bg.setOpacity(0.0);
block.setPriceLabel();
block._priceLabel.setOpacity(0.0);
this._blocks[i][j] = block;
this.LAND_BLOCK_TAG++;
blockCounter++;
}
}
}
And same code is working fine with cocos2d-x(c++).
Thanks.
After lots of tweaks and googling, i just used lower version of cocos2d-html(version 3.7). And same code work as expected.There might be problem in rendering pipeline in latest cocos2d-html. And same issue persist in case we try to make Grid of UI component or Basic components(Sprite,Label) as components number increases positioning difference increases(i.e as show in reference image).

Leaflet Delete polyline between 2 markers

How I can delete the polyline line between 2 specific marker.
I have many polyline connected with many marker . But i want to delete any sspecific line on double click .
How Can I do that ?
I am using leaflet to draw the polyline.
here suppose I want to delete the polyline between marker 3 and 4 on double click. what will be procedure to do that.
Thank you.
I tried something like this but its not working , Can anybody please help me where is the mistakes ?
//polyline delete on double click
for (var i = 0; i < $scope.polycoords.length; i++) {
var polyline = $scope.polycoords[i];
$scope.polycoords[i].on('click', function (e) {
console.log("sdd",polyline._leaflet_id);
for (var j = 0; j < $scope.polycoords.length; j++) {
if($scope.polycoords[i]._leaflet_id = $scope.polycoords[j]._leaflet_id){
console.log($scope.polycoords[j])
var polyline = $scope.polycoords[j];
map.removeLayer(polyline);
}
}
});
}
polyline.on('dblclick', function (e) {
map.removeLayer(this);
});
Edit
This is going to work because based on your other question here on SO, I know that you create a different polyline for each line. But for anyone else that creates a single polyline with all the coordinates together, this solution will delete the whole polyline, not just a part of it.

remove graphics from inside a class as3

When I click a button in my game it draws shapes using the graphics in as3. simple shapes such as circles and rectangles.
I want to remove the graphics that have been drawn when something happens in one of my classes.
Basically when there is a hitTestObject (which works fine) I want all graphics on stage to be cleared.
if (gb2.hitTestObject(h1s2))
{
trace ("holed")
ySpeed2=0;
xSpeed2=0;
this.visible=false;
var mcSplash:MovieClip =parent.getChildByName("mcSplash") as MovieClip;
mcSplash.visible=true;
//parent.drawings.graphics.clear();
}
My attempt using parent.drawings.graphics.clear(); was unsuccessful, it gives me this error:
Line 481 1119: Access of possibly undefined property drawings through a reference with static type flash.display:DisplayObjectContainer.
Anyone have any suggestions
UPDATE:
this is how, on the min time line, the drawings occur.
var drawings:Shape = new Shape;
for (i=0; i<numRecs; i++)
{
recStartX = Number(xmlContent.rec[i].startpoint.#ptx);
recStartY = Number(xmlContent.rec[i].startpoint.#pty);
recWidth = Number(xmlContent.rec[i].dimensions.#w);
recHeight = Number(xmlContent.rec[i].dimensions.#h);
fillColor=int(xmlContent.rec[i].look.fillhex);
lineThick = Number(xmlContent.rec[i].look.strokethick);
lineColor = int(xmlContent.rec[i].look.strokehex);
drawings.graphics.lineStyle(lineThick, lineColor);
drawings.graphics.beginFill(fillColor);
drawings.graphics.drawRect(recStartX,recStartY,recWidth,recHeight);
drawings.graphics.endFill();
}
Create an array and push in each shape/rect.
Then iterate through this and remove..
for(var iteration:int = 0; iteration < rectArray.length; iteration++)
this.removeChild(rectArray[iteration]);
or if you are calling this from a class, use
MovieClip(this.root).removeChild(rectArray[iteration]);
Hopefully this is helpful :)
Z
What's drawings?! If you draw in mcSplash, you should use mcSplash.graphics.clear(). If you draw in a child called drawings, you should first get it as a child (after mcSplash get): var drawings = mcSplash.getChildByName('drawings); drawings.graphics.clear();. You could write checks to see what's going on: if (mcSlpash) { if (drawings) {, etc..

Flash : How to write roll over coding for grid in array which is similar colour movieclips nearby?

Flash AS3:
I just need to know how to check a condition for roll over effect on similar colour movieclips which is near by in a group of random colours movieclips in a grid whereas it is using 2D Array in flash AS3.or
I just need roll over event which i wrote is onBoxOver event function, in that the object which i am targetting is only getting rollover or getting alpha changes. But i need to know how to make rollover for similar colour which are all nearby.
The code which i wrote is below for your reference.
Flash AS3::
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class playGame extends MovieClip
{
public static var totalRowBoxes:Number = 13;
public static var totalColumnBoxes:Number = 12;
public static var rowGap:Number = 30;
public static var columnGap:Number = 30;
public static var totalColorBoxes:Number = 8;
public static var boxCollection:Array = new Array();
public static var boxCollection1:Array = new Array();
public function playGame(theGame:main)
{
// constructor code
addBoxOnStage();
}
private function addBoxOnStage():void
{
var borderCont:Banner = new Banner();
var scoreclipCont:scoreclip = new scoreclip();
addChild(borderCont);
addChild(scoreclipCont);
scoreclipCont.x = 0;
scoreclipCont.y = 0;
createLevel(1);
for (var i:Number = 0; i<totalRowBoxes; i++)
{
boxCollection[i] = new Array(i);
for (var j:Number = 0; j<totalColumnBoxes; j++)
{
var squareCont:square = new square();
squareCont.x = 30 + (i * rowGap);
squareCont.y = 30 + (j * columnGap);
squareCont.name = i + "_" + j;
var boxCollection1:Array = new Array();
boxCollection1[0] = Math.round(Math.random() * 8);
boxCollection1[1] = squareCont;
var boxColour:Number = new Number();
boxColour = boxCollection1[0];
boxCollection[i][j] = boxCollection1[1];
addChild(squareCont);
squareCont.gotoAndStop(boxCollection1[0]);
squareCont.addEventListener(MouseEvent.MOUSE_OVER, onBoxOver); squareCont.addEventListener(MouseEvent.MOUSE_OUT, onBoxOut);
squareCont.addEventListener(MouseEvent.CLICK, onBoxClick);
}
}
}
private function onBoxClick(eve:MouseEvent):void
{
}
private function onBoxOver(eve:MouseEvent):void
{
for (var i:Number=0; i< totalRowBoxes; i++)
{
for (var j:Number=0; j<totalColumnBoxes; j++)
{
eve.target.alpha = 0.3;
// trace(boxCollection[i][j].currentFrame)
trace(eve.target);
}
}
}
private function onBoxOut(eve:MouseEvent):void
{
eve.target.alpha = 1;
}
private function createLevel(lvl):void
{
}
}
}
![My Game screenshot here colourbox][1]
Thanks in Advance. Greatly Appreciable for the reply.
Hi this is the image or screenshot of my project. In that image there are 8 colours randomly arranged. whenever i make mouse position or rollover on any box , the condition should check whether the same colour occurs around the box(eg.top, down, left, right) which i am making rollover.
1.If the same colour occur on the top of the box which i am pointing the cursor , the top box and the box which i am pointing both should get less alpha, else only the pointing box should get less alpha. this is my concept friends. please go through the image and let me know if u have any doubts.
I am still unsure what you mean by 'nearby'. (neighbour tiles? adjacent of similar colour?...)
If 'nearby' means adjacent, you need to read about flood fill algorithms. There is a good wiki article about this. You would use that to crawl through the list of tiles similar enough to trigger the effect you want.
I also don't know what 'similar' colour means in your project. You will need a method to determine weather two colours are similar. There is a stackoverflow question re: similar colour detection. It has a good answer to start you out in your research. look here.