3

I have a json file with large geometries(MultiLineString), here I got a Point among the json layer(baseLayer). I would like to search for a Point's LineString in the layer, from which MultiLineString that Point been selected. And how to read a json file in OpenLayers/JavaScript

I can project the json file in OpenLayers, but when I click the map I am getting the Point, from that Point I would like to search for its base geometry(LineString/MultiLineString)

Thank you

  • Please provide your code in JS Fiddle – Sunil Jan 2 '13 at 9:29
3

you can read json file in openlayers with OpenLayers.Format.GeoJSON().

  jsLayer = new OpenLayers.Layer.Vector("MyLayer", {
        strategies: [new OpenLayers.Strategy.Fixed()],
        projection: map.displayProjection,
        protocol: new OpenLayers.Protocol.HTTP({
            url: "jsons/roads.json",
            format: new OpenLayers.Format.GeoJSON()
        })
    });

UPDATE:

Searching point from another layer:

  layer.events.on({
        "featureselected": function(e) {    
             var mlFeat = multiLayer.features // Another Layer Features
             for(var a=0; a<mlFeat.length; a++){
                   var mlGeom = mlFeat[a].geometry;
                   if(e.geometry.x == mlGeom.x || e.geometry.y == mlGeom.y){
                      alert('Your Features')
                       }
                          }             
        }
      }); 

i hope it helps you...

|improve this answer|||||
  • Perfect answer : ) – Sunil Jan 2 '13 at 9:26
  • I can project the json file OpenLayers, but when I click the map I am getting the Point from the Point I would like to search for its base geometry(LineString/MultiLineString) – GOVINDA Jan 2 '13 at 9:28
0

Well if you want to select/find a feature you clicked can use the built in OpenLayers.Control.SelectFeature.

var selectfeature = new OpenLayers.Control.SelectFeature(    
  <OpenLayers.Layer.Vector>
 ,{ 
    multiple: false 
   ,onSelect: function( feature )
    {
      //feature already identified to you, do not need do point run
    }
  } 
);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.